/* Example program for the KPCI-PDISO8A Uses the Direct I/O COM API of the DriverLINX driver. Tested using a KPCI-PDISO8A in Win2K SP1 using ISO-850A01 version of DriverLINX The Direct I/O COM API is similar to register level control. All reads or writes are referenced to the base address. However, this API requires only that you specify the offset from the base address.....you don't need to know where the base address actually is (the driver knows). The 8 lines of digital input are at an offset of 0 (Read Only) The 8 relay outputs are at an offset of 4 (Read/Write). Write a value between 0 and 255 to control the relays at this address. This offset can also be read to "read back" the state of the relays. */ #include #include // change path below as necessary for your installation... #import"c:\drvlinx4\common\kdigio.dll" using namespace KDIGIOLib; int main() { unsigned char data; if(FAILED(CoInitialize(NULL))) { cout << "Unable to initialize COM" << endl; return 1; } try { // smart pointer declaration will create an instance of the object. IKDigitalIoPtr pdio(__uuidof(KDIGIOLib::KDigitalIo) ); pdio->OpenDevice("kpciiso",0); // open a session for board configured as Device 0 in DLinx Config cout << "Closing relay 0, OP0....look for appx 3 ohms between pins 18 and 36." << endl; cout << "Hit Enter to continue..." << endl; cout << endl; cout << endl; pdio->Write (4,1); // write a 1 to offset of 4 to close the LSB getch(); cout << "Opening relay 0, OP0....look for infinate ohms between pins 18 and 36." << endl; cout << "Hit Enter to continue..." << endl; cout << endl; cout << endl; pdio->Write (4,0); // write a 0 to offset of 4 to open the LSB getch(); cout << "Now reading the digital input channel....." << endl; data=pdio->Read(0); //read in the value of the digital inputs cout << "Digital Input value = 0x" << hex << static_cast(data) << endl; cout << "Hit Enter to continue..." << endl; cout << endl; cout << endl; getch(); } catch (const _com_error& Err) { cout << "Error using Direct I/O" << endl; cout << "Error number is 0x" << hex << Err.Error() << endl; cout << "Error message is " << Err.ErrorMessage() << endl; // Display error description if rich error info supported if (Err.ErrorInfo()) cout << Err.Description() << endl; return 1; } // Closes the COM library on the current thread, // unloads all DLLs loaded by the thread, // frees any other resources that the thread maintains, // and forces all RPC connections on the thread to close. cout << "Closing COM" << endl; CoUninitialize(); cout << "Hit to exit..." << endl; //getch(); return 0; }